// 简化的测试脚本
const mysql = require('mysql2/promise');
const config = require('./config');

async function testDatabase() {
    try {
        console.log('开始测试数据库连接...');
        
        // 创建数据库连接
        const connection = await mysql.createConnection({
            host: config.DATABASE.host,
            user: config.DATABASE.user,
            password: config.DATABASE.password,
            database: config.DATABASE.database
        });
        
        console.log('数据库连接成功！');
        
        // 测试插入歌名
        console.log('测试插入歌名...');
        const songResult = await connection.execute(
            'INSERT INTO songs (name) VALUES (?)',
            ['测试歌曲']
        );
        console.log('歌名插入成功，ID:', songResult[0].insertId);
        
        // 测试插入原唱
        console.log('测试插入原唱...');
        const singerResult = await connection.execute(
            'INSERT INTO songers (name) VALUES (?)',
            ['测试歌手']
        );
        console.log('原唱插入成功，ID:', singerResult[0].insertId);
        
        // 测试查询
        console.log('测试查询歌名...');
        const songs = await connection.execute('SELECT * FROM songs');
        console.log('歌名列表:', songs[0]);
        
        console.log('测试查询原唱...');
        const singers = await connection.execute('SELECT * FROM songers');
        console.log('原唱列表:', singers[0]);
        
        await connection.end();
        console.log('数据库测试完成！');
        
    } catch (error) {
        console.error('数据库测试失败:', error);
    }
}

testDatabase();